package licode.unisop.single.user.infrastructure.repository.dao;

import licode.unisop.unilite.result.UniException;
import lombok.Getter;

/**
 * 账号类型
 *
 * @author licode
 */
@Getter
public class AccountCategory {

    public static final AccountCategory EMAIL = new AccountCategory("email");
    public static final AccountCategory MOBILE = new AccountCategory("mobile");
    public static final AccountCategory ACCOUNT = new AccountCategory("account");
    public static final AccountCategory WEI_XIN = new AccountCategory("wx");
    public static final AccountCategory ID_CARD = new AccountCategory("id_card");

    private final String category;

    private AccountCategory(String category) {
        this.category = category;
    }

    public static AccountCategory build(String category) throws UniException {
        if (EMAIL.category.equals(category)) {
            return AccountCategory.EMAIL;
        } else if (MOBILE.category.equals(category)) {
            return AccountCategory.MOBILE;
        } else if (ACCOUNT.category.equals(category)) {
            return AccountCategory.ACCOUNT;
        } else if (WEI_XIN.category.equals(category)) {
            return AccountCategory.WEI_XIN;
        } else if (ID_CARD.category.equals(category)) {
            return AccountCategory.ID_CARD;
        } else {
            throw new UniException(-1, "错误的账号类别");
        }
    }

    public boolean isEmail() {
        return EMAIL.category.equals(category);
    }

    public boolean isMobile() {
        return MOBILE.category.equals(category);
    }

    public boolean isAccount() {
        return ACCOUNT.category.equals(category);
    }

    public boolean isWx() {
        return WEI_XIN.category.equals(category);
    }

    public boolean isIdCard() {
        return ID_CARD.category.equals(category);
    }

    public boolean equals(String other) {
        return this.category.equals(other);
    }

    @Override
    public String toString() {
        return category;
    }
}
